//
// Created by yangchao on 2022/5/15.
// 98. 验证二叉搜索树: https://leetcode.cn/problems/validate-binary-search-tree/
//

#include "../DataStructure/TreeNode.h"
#include <stack>
#include <climits>

using namespace std;

class IsValidBST {
public:
    bool isValidBST(TreeNode* root) {
        stack<TreeNode*> stk;
        long inorder = LONG_MIN;
        TreeNode* node = root;
        while (node != nullptr || !stk.empty()) {
            while (node != nullptr) {
                stk.push(node);
                node = node->left;
            }
            node = stk.top();
            stk.pop();
            if (node->val <= inorder) return false;
            inorder = node->val;
            node = node->right;
        }
        return true;
    }
};

